const mongoose = require("mongoose");
//链接数据库
mongoose.connect('mongodb://localhost/test', { useNewUrlParser: true });

//规定数据类型
const catSchema = new mongoose.Schema({
    name: { type: String, required: true },
    age: Number,
    date: { type: Date, default: Date.now }
});

//链接数据表，并且规定数据的类型
const Cat = mongoose.model('Cat1', catSchema);
//使用数据表
const kitty = new Cat({ name: 'Zildjian', age: 20 });
//保存数据
kitty.save().then((res) => console.log(res));